package com.aaa.service.yy.impl;

import cn.hutool.core.bean.BeanUtil;
import com.aaa.dao.yy.TesterSdsDao;
import com.aaa.dao.yy.ViewResultSdsDao;
import com.aaa.pojo.TesterFpa;
import com.aaa.pojo.TesterVo;
import com.aaa.pojo.yy.TesterSds;
import com.aaa.pojo.yy.ViewResultSds;
import com.aaa.service.yy.ResultSdsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class ResultSdsServiceImpl implements ResultSdsService {
    @Autowired
    private TesterSdsDao testerSdsDao;
    @Autowired
    private ViewResultSdsDao viewResultSdsDao;
    @Override
    public String saveTestResult(List<Map<String, Object>> answerList, TesterVo tester) {
        TesterSds testerSds = new TesterSds();

        BeanUtil.copyProperties(tester,testerSds,"id");
       // System.out.println(testerSds);
        testerSdsDao.insert(testerSds);
        int testerId = testerSds.getId();
        System.out.println(testerId);
        int i = insertBatch(answerList, testerId);
        //System.out.println(i);
        if(i > 0){
            return selectResult(testerId);
        }
        return null;
    }

    @Override
    public int insertBatch(List<Map<String, Object>> answerList, int testerId) {
        return testerSdsDao.insertBatch(answerList,testerId);
    }

    @Override
    public String selectResult(int testerId) {
       // System.out.println(testerId);
        ViewResultSds viewResultSds = viewResultSdsDao.selectResultSas(testerId);
       // System.out.println(viewResultSds);
        double a = viewResultSds.getForward() + viewResultSds.getInversion();
        System.out.println(a);
        if (a <= 53) {
            return "/view/SdsNormal.jsp";
        } else if (a < 62) {
            return "/view/SdsMild.jsp";
        } else if (a < 72) {
            return "/view/SdsModerate.jsp";
        } else {
            return "/view/SdsSevere.jsp";
        }

    }
}
